var myChart;

// post请求封装
// function post(url,data) {
// 	let baseUrl='http://192.168.3.135:8080';
// 	return new Promise((resolve,reject)=>{
// 		axios({
// 			headers:{
// 				"Content-Type": "application/x-www-form-urlencoded",
// 			},
// 			method:'post',
// 			url:baseUrl+url,
// 			data:Qs.stringify( data || {})
// 		})
// 		.then(res=>{
// 			console.log(res)
// 			if(res.data.code==1){
// 				resolve(res.data)
// 			}else{
// 				reject()
// 				alertError('请求超时')
// 			}
// 		})
// 		.catch(err=>{
// 			alertError('请求超时')
// 		})
// 	})
// }

//title
function getTitle(top, left, text) {
	var title = {
		top: top,
		left: left,
		text: text,
		textStyle: {
			color: '#F1F3F4',
			fontWeight: 400,
			fontSize: 12
		}
	};
	return title;
}
//dataZoom
function getDataZoom() {
	var dataZoom = [{
		type: 'slider',
		show: true,
		height: 20,
		left: '10%',
		right: '10%',
		bottom: '2%',
		start: 0,
		end: 100,
		textStyle: {
			color: '#d4ffff',
			fontSize: 11
		}
	}, {
		type: 'inside'
	}];
	return dataZoom;
}
//grid
function getGrid() {
	var grid = {
		right: '5%',
		bottom: '10%',
		left: '2%',
		top: '40px',
		containLabel: true
	};
	return grid;
}
//通用x轴处理
function getXAxis(data, name) {
	var xAxis = [{
		type: 'category',
		data: data,
		name: name,
		nameTextStyle: {
			color: '#d4ffff'
		},
		axisLine: {
			lineStyle: {
				color: "#ffffff"
			}
		},
		splitLine: {
			show: true,
			lineStyle: {
				color: "rgba(255,255,255,0.2)"
			}
		},
		axisTick: {
			show: false
		}
	}];
	return xAxis;
}
//通用y轴处理
function getYAxis(name) {
	var yAxis = [{
		type: 'value',
		name: name,
		nameTextStyle: {
			color: '#d4ffff'
		},
		position: 'left',
		splitLine: {
			show: true,
			lineStyle: {
				color: "rgba(255,255,255,0.2)"
			}
		},
		axisLine: {
			lineStyle: {
				color: "#ffffff"
			}

		}
	}];
	return yAxis;
}
//serie
function getSerie(yData1) {
	var serie = [{
		name: '',
		type: 'line',
		yAxisIndex: 0,
		symbolSize: 10,
		symbol: 'circle',
		itemStyle: {
			normal: {
				color: '#00FF00'
			}
		},
		data: yData1
	}];
	return serie;
}
//legend
function getLegend(data) {
	var legend = {
		x: '8%',
		top: '11%',
		textStyle: {
			color: '#90979c'
		},
		icon: 'circle',
		data: data
	};
	return legend;
}


// 弹窗
function alertError(title) {
	document.addEventListener('plusready', function() {
		console.log('......')
	})
	try {
		plus.nativeUI.toast(title, {
			icon: '/static/common/toast-error.png',
			style: 'inline',
			verticalAlign: 'top'
		});
	} catch (e) {
		//TODO handle the exception
	}
}
var app = new Vue({
	el: '#app',
	data: {
		MA5: '',
		MA10: '',
		MA30: '',
		volMA5: '',
		volMA10: '',
		current: 1,
		tabs: [{
				'label': '400',
				'value': 1
			},
			{
				'label': '1200',
				'value': 2
			},
			{
				'label': '3600',
				'value': 3
			},
			{
				'label': '10800',
				'value': 4
			},
			{
				'label': '25600',
				'value': 5
			},
			// {'label':'多时域波形','value':6},
		],
		category: 1,
		categoryList: [{
				'label': '标注',
				'value': 1
			},
			{
				'label': '历史数据',
				'value': 2
			},
			{
				'label': '测点详情',
				'value': 3
			},
		],
		txData: {}, //交易数据统计
		buyList: [],
		sellList: [],
		dealHis: [],
		tokenInfo: {},
		page: 1,

	},
	created() {
		this.getTxData()
		this.getDepth()
	},
	mounted() {},
	methods: {
		// 返回上一页
		back() {
			uni.navigateBack()
		},
		// 获取24小时交易数据统计
		getTxData() {
			this.txData = txData;
		},
		// 列表条数不足补全
		addItem(list, type) {
			// type: 1开头加，2末尾加
			list = list || [];
			let len = 20 - list.length;
			if (len > 0) {
				for (let i = 0; i < len; i++) {
					if (type == 1) {
						list.unshift({})
					} else {
						list.push({})
					}
				}
			}
			return list;
		},

		// 切换tab
		switchTab(val) {
			if (this.current == val) return;
			this.current = val;
			// this.getKline()
			var switchTabValue = this.tabs[this.current].value
			if (switchTabValue == 1) {
		
			} else if (switchTabValue == 2) {
				var shiyu_str = localStorage.getItem("shiyu");
				var shiyu_json = JSON.parse(shiyu_str);
			} else if (switchTabValue == 3) {
		
			} else if (switchTabValue == 4) {
		
			} else {
		
			}
		
		},

		// 获取设备树
		click_tree() {
			debugger

		},
		getDepth() {
			this.buyList = this.addItem(depthList().buyList || []);
			this.sellList = this.addItem(depthList().sellList || []);
		},
		// 获取成交记录
		getDealHis() {
			this.dealHis = dealHis();
		},
		// 获取项目简介信息
		getTokenInfo() {
			this.tokenInfo = tokenInfo;
		},

		// 切换类目
		switchCategory(val) {
			if (this.category == val) return;
			this.category = val;
			if (this.category == 1) {
				this.getDepth()
			} else if (this.category == 2) {
				this.getDealHis()
			} else {
				this.getTokenInfo()
			}
		},
		// 截取数字字符串 保留precision小数
		formatterNum(value, precision) {
			// console.log(value)
			let reg = new RegExp('^\\d+(?:\\.\\d{0,' + precision + '})?')
			return value.toString().match(reg)
		},
		// 计算MA
		calculateMA(dayCount, data) {
			var result = [];
			for (var i = 0, len = data.length; i < len; i++) {
				if (i < dayCount) {
					result.push('-');
					continue;
				}
				var sum = 0;
				for (var j = 0; j < dayCount; j++) {
					sum += data[i - j][1];
				}
				// console.log(sum, dayCount)
				result.push((sum / dayCount).toFixed(2));
			}
			return result;
		},
	}
})
